﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SWDataDB.Models;
using SWDataDB.DAL;
using System.Data;

namespace SWDataDB.BLL
{
    // 区调相关数据查找
    public class QDAdvanceQuery
    {
        #region ===以著录表的档号为外键，查找相关的表,返回DataSet===
        /// <summary>
        /// 剖面表查询
        /// </summary>
        /// <param name="strZL"></param>
        /// <returns></returns>
        public DataSet PMInfoQuery(string file_id)
        {
            string strWhere;
            if (string.IsNullOrEmpty(file_id))
            {
                strWhere = "";
            }

            else
            {
                strWhere = "ZL_FILE_ID='" + file_id + "'";
            }
            PMInfo pm_info = new PMInfo();

            return pm_info.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 其它实物查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public DataSet UTILAdvancedQuery(string file_id)
        {
            string strWhere;
            if (string.IsNullOrEmpty(file_id))
            {
                strWhere = "";
            }

            else
            {
                strWhere = "ZL_FILE_ID='" + file_id + "'";
            }
            UTILInfo info = new UTILInfo();

            return info.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 相关文件查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public DataSet XGAdvancedQuery(string file_id)
        {
            string strWhere;
            if (string.IsNullOrEmpty(file_id))
            {
                strWhere = "";
            }

            else
            {
                strWhere = "ZL_FILE_ID='" + file_id + "'";
            }
            XGInfo info = new XGInfo();

            return info.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 标本表查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public DataSet BBAdvancedQuery(string file_id)
        {
            string strWhere;
            if (string.IsNullOrEmpty(file_id))
            {
                strWhere = "";
            }

            else
            {
                strWhere = "ZL_FILE_ID='" + file_id + "'";
            }
            BBInfo bbInfo = new BBInfo();

            return bbInfo.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 薄片查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public DataSet BPAdvancedQuery(string file_id)
        {
            string strWhere;
            if (string.IsNullOrEmpty(file_id))
            {
                strWhere = "";
            }

            else
            {
                strWhere = "ZL_FILE_ID='" + file_id + "'";
            }
            BPInfo bpinfo = new BPInfo();
            return bpinfo.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 光片查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public DataSet GPAdvancedQuery(string file_id)
        {
            string strWhere;
            if (string.IsNullOrEmpty(file_id))
            {
                strWhere = "";
            }

            else
            {
                strWhere = "ZL_FILE_ID='" + file_id + "'";
            }
            GPInfo gpinfo = new GPInfo();
            return gpinfo.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 样品查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public DataSet YPAdvancedQuery(string file_id)
        {
            string strWhere;
            if (string.IsNullOrEmpty(file_id))
            {
                strWhere = "";
            }

            else
            {
                strWhere = "ZL_FILE_ID='" + file_id + "'";
            }
            YPInfo ypinfo = new YPInfo();
            return ypinfo.GetInfoForPageByASC(strWhere);
        }

        #endregion

        #region ===以关键字段，查找相关的表，返回dataset===

        /// <summary>
        /// 剖面表查询
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public DataSet PMInfoQuery(string file_id, string title, string pm_code, string pm_name, string zl, string scale,
            string start_lat, string end_lat, string start_lon, string end_lon)
        //strFileID, strtitleName, strPMCODE, strPMName, strPMQuality, strPMScale, strPMSLON1, strPMSLON2, strPMSLAT1, strPMSLAT2
        {
            string strWhere = string.Empty;
            strWhere += " 1=1 AND ";
            if (!string.IsNullOrEmpty(pm_code))
                strWhere += "PM_CODE like '%" + pm_code + "%' AND ";
            if (!string.IsNullOrEmpty(pm_name))
                strWhere += "PM_NAME like '%" + pm_name + "%' AND ";
            if (!string.IsNullOrEmpty(zl))
                strWhere += "PM_QUALITY like '%" + zl + "%' AND ";
            if (!string.IsNullOrEmpty(scale))
                strWhere += "SCALE = " + scale.ToString() + " AND ";
            if (!string.IsNullOrEmpty(start_lat))
                strWhere += "PM_SLAT > " + start_lat.ToString() + " AND ";
            if (!string.IsNullOrEmpty(end_lat))
                strWhere += "PM_SLAT < " + end_lat.ToString() + " AND ";
            if (!string.IsNullOrEmpty(start_lon))
                strWhere += "PM_SLON > " + start_lon.ToString() + " AND ";
            if (!string.IsNullOrEmpty(end_lat))
                strWhere += "PM_SLON < " + end_lat.ToString() + " AND ";
            if (!string.IsNullOrEmpty(file_id))
                strWhere += "ZL_FILE_ID like '%" + file_id + "%' AND ";
            if (!string.IsNullOrEmpty(title))
                strWhere += "ZL_FILE_ID IN (SELECT FILE_ID FROM ZL_TBL WHERE (TITLE like '%" + title + "%')) AND ";
            PMInfo pm_info = new PMInfo();

            strWhere = strWhere = strWhere.Remove(strWhere.Length - 5, 4);
            return pm_info.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 其它实物查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <param name="type"></param>
        /// <param name="cj_name"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public DataSet UTILAdvancedQuery(string file_id, string type, string cj_name, string date)
        {
            string strWhere = string.Empty;
            if (!string.IsNullOrEmpty(file_id))
                strWhere += "ZL_FILE_ID like '%" + file_id + "%' AND ";
            if (!string.IsNullOrEmpty(type))
                strWhere += "SW_TYPE like '%" + type + "%' AND ";
            if (!string.IsNullOrEmpty(cj_name))
                strWhere += "COL_NAME like '%" + cj_name + "%' AND ";
            if (!string.IsNullOrEmpty(date))
                strWhere += "COL_DATE='" + date + "' AND ";
            UTILInfo info = new UTILInfo();

            strWhere = strWhere.Remove(strWhere.Length - 5, 4);
            return info.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 相关文件查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <param name="code"></param>
        /// <param name="style"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public DataSet XGAdvancedQuery(string file_id, string code, string style, string name)
        {
            string strWhere = string.Empty;

            if (!string.IsNullOrEmpty(file_id))
                strWhere += "ZL_FILE_ID like '%" + file_id + "%' AND ";
            if (!string.IsNullOrEmpty(code))
                strWhere += "XG_CODE like '%" + code + "%' AND ";
            if (!string.IsNullOrEmpty(style))
                strWhere += "DATA_STYLE like '%" + style + "%' AND ";
            if (!string.IsNullOrEmpty(name))
                strWhere += "DATA_NAME like '%" + name + "%' AND ";

            XGInfo info = new XGInfo();

            strWhere = strWhere.Remove(strWhere.Length - 5, 4);
            return info.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 标本表查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <param name="title"></param>
        /// <param name="bb_id"></param>
        /// <param name="bb_name"></param>
        /// <param name="pos"></param>
        /// <param name="way"></param>
        /// <param name="out_name"></param>
        /// <param name="in_name"></param>
        /// <returns></returns>
        public DataSet BBAdvancedQuery(string file_id, string title, string bb_id, string bb_name, string pos, string way,
            string out_name, string in_name)
        {
            string strWhere = string.Empty;

            if (!string.IsNullOrEmpty(bb_id))
                strWhere += "BB_CODE like '%" + bb_id + "%' AND ";
            if (!string.IsNullOrEmpty(bb_name))
                strWhere += "BB_NAME like '%" + bb_name + "%' AND ";
            if (!string.IsNullOrEmpty(pos))
                strWhere += "CY_POS like '%" + pos + "%' AND ";
            if (!string.IsNullOrEmpty(way))
                strWhere += "QY_METHOD like '%" + way + "%' AND ";
            if (!string.IsNullOrEmpty(out_name))
                strWhere += "OUT_NAME like '%" + out_name + "%' AND ";
            if (!string.IsNullOrEmpty(in_name))
                strWhere += "INNAR_NAME like '%" + in_name + "%' AND ";
            if (!string.IsNullOrEmpty(file_id))
                strWhere += "ZL_FILE_ID like '%" + file_id + "%' AND ";
            if (!string.IsNullOrEmpty(title))
                strWhere += "ZL_FILE_ID IN (SELECT FILE_ID FROM ZL_TBL WHERE (TITLE like '%" + title + "%') AND ";
            BBInfo bbInfo = new BBInfo();

            strWhere = strWhere.Remove(strWhere.Length - 5, 4);

            return bbInfo.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 薄片查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <param name="title"></param>
        /// <param name="bp_code"></param>
        /// <param name="bp_name"></param>
        /// <param name="pm_name"></param>
        /// <param name="pm_code"></param>
        /// <returns></returns>
        public DataSet BPAdvancedQuery(string file_id, string title, string bp_code, string bp_name, string pm_code, string pm_name)
        {
            string strWhere = string.Empty;

            if (!string.IsNullOrEmpty(bp_code))
                strWhere += "BP_CODE like '%" + bp_code + "%' AND ";
            if (!string.IsNullOrEmpty(bp_name))
                strWhere += "BP_NAME like '%" + bp_name + "%' AND ";
            if (!string.IsNullOrEmpty(pm_name))
                strWhere += "PM_PATH_NAME like '%" + pm_name + "%' AND ";
            if (!string.IsNullOrEmpty(pm_code))
                strWhere += "PM_PATH_NUM like '%" + pm_code + "%' AND ";
            if (!string.IsNullOrEmpty(file_id))
                strWhere += "ZL_FILE_ID like '%" + file_id + "%' AND ";
            if (!string.IsNullOrEmpty(title))
                strWhere += "ZL_FILE_ID IN (SELECT FILE_ID FROM ZL_TBL WHERE (TITLE like '%" + title + "%') AND ";
            BPInfo bpinfo = new BPInfo();

            strWhere = strWhere.Remove(strWhere.Length - 5, 4);
            return bpinfo.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 光片查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public DataSet GPAdvancedQuery(string file_id, string title, string gp_code, string gp_name, string pm_code, string pm_name)
        {
            string strWhere = string.Empty;

            if (!string.IsNullOrEmpty(gp_code))
                strWhere += "GP_CODE like '%" + gp_code + "%' AND ";
            if (!string.IsNullOrEmpty(gp_name))
                strWhere += "GP_NAME like '%" + gp_name + "%' AND ";
            if (!string.IsNullOrEmpty(pm_name))
                strWhere += "PM_PATH_NAME like '%" + pm_name + "%' AND ";
            if (!string.IsNullOrEmpty(pm_code))
                strWhere += "PM_PATH_NUM like '%" + pm_code + "%' AND ";
            if (!string.IsNullOrEmpty(file_id))
                strWhere += "ZL_FILE_ID like '%" + file_id + "%' AND ";
            if (!string.IsNullOrEmpty(title))
                strWhere += "ZL_FILE_ID IN (SELECT FILE_ID FROM ZL_TBL WHERE (TITLE like '%" + title + "%') AND ";
            GPInfo gpinfo = new GPInfo();

            strWhere = strWhere.Remove(strWhere.Length - 5, 4);
            return gpinfo.GetInfoForPageByASC(strWhere);
        }

        /// <summary>
        /// 样品查找
        /// </summary>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public DataSet YPAdvancedQuery(string file_id, string title, string yp_code, string yp_name, string pm_code, string pm_name,
                        string out_name, string in_name)
        {
            string strWhere = string.Empty;

            if (!string.IsNullOrEmpty(yp_code))
                strWhere += "YP_CODE like '%" + yp_code + "%' AND ";
            if (!string.IsNullOrEmpty(yp_name))
                strWhere += " YP_NAME like '%" + yp_name + "%' AND ";
            if (!string.IsNullOrEmpty(pm_name))
                strWhere += " PM_PATH_NAME like '%" + pm_name + "%' AND ";
            if (!string.IsNullOrEmpty(pm_code))
                strWhere += " PM_PATH_NUM like '%" + pm_code + "%' AND ";
            if (!string.IsNullOrEmpty(out_name))
                strWhere += " OUT_NAME like '%" + out_name + "%' AND ";
            if (!string.IsNullOrEmpty(in_name))
                strWhere += "INNAR_NAME like '%" + in_name + "%' AND ";
            if (!string.IsNullOrEmpty(file_id))
                strWhere += "ZL_FILE_ID like '%" + file_id + "%' AND ";
            if (!string.IsNullOrEmpty(title))
                strWhere += "ZL_FILE_ID IN (SELECT FILE_ID FROM ZL_TBL WHERE (TITLE like '%" + title + "%') AND ";
            YPInfo ypinfo = new YPInfo();

            strWhere = strWhere.Remove(strWhere.Length - 5, 4);
            return ypinfo.GetInfoForPageByASC(strWhere);
        }
        #endregion
    }
}
